home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / samples / zscript / misc.zsc.z / misc.zsc
Encoding:
Text File  |  1997-01-22  |  3.7 KB  |  161 lines

  1. # Miscellaneous Z-Script sample functions
  2.  
  3. function show_all_subjs() {
  4.     msg_list + $*
  5.     pick -s $[%s] | save +$[%s]:1
  6.     if X$output == X
  7.     eval -p error "Error trying to find messages with subject\n$[%s]"
  8.     else
  9.     open +[$%s]:1
  10.     endif
  11. }
  12. button "All Subjects" show_all_subjs
  13.  
  14. function gui_edit_msg() {
  15.     copy $1 /tmp/msg$1.$$ | delete
  16.     sh $window_shell $visual /tmp/msg$1.$$
  17.     merge /tmp/msg$1.$$
  18. }
  19. function loop_edit_msg() {
  20.     foreach msg $* 'gui_edit_msg $msg'
  21. }
  22. button "Edit Message" loop_edit_msg
  23.  
  24. function backtrack() {
  25.     pick -r ^-. -1 -h message-id $* | mark
  26.     return 0
  27. }
  28.  
  29. function prev_reference() {
  30.     msg_list - $*   # set current message
  31.     unmark *        # clear temporary marks
  32.     foreach ref ($[%?references?]) 'backtrack $ref'
  33.     msg_list `:m`
  34.     if "X$output" == X
  35.     error "No previous reference found."
  36.     else
  37.     unmark `:m` | pick -1
  38.     endif
  39. }
  40.  
  41. function read_prev_ref() {
  42.     prev_reference $*
  43.     if $status == 0
  44.     read $output
  45.     endif
  46. }
  47. button "Previous Reference" read_prev_ref
  48.  
  49. function create_alias() {
  50.     msg_list - $*                       # Make sure current message is set
  51.     set name="$[%n]" address="$[%f]"    # Grab name and From: from message
  52.     if "X$name" == X
  53.     ask -i name \
  54.     "Can't find this sender's name.\nWhat should I call the alias?"
  55.     if $status != 0
  56.         return -1
  57.     endif
  58.     endif
  59.     alias $name:1 "$address"    # alias person's first name to his address
  60. }
  61. button CreateAlias create_alias
  62.  
  63. function use_as_composition() {
  64. #%
  65. #      use_as_composition [messagelist]
  66. #
  67. # Use each of the messages in messagelist (or the current message) as the
  68. # headers and body of a new composition.  Creates one composition for each
  69. # message in the list.  If attached to a GUI button, the selected messages
  70. # from the Main Window Message Summaries are used.
  71. #%
  72.     msg_list $*
  73.     foreach msg $output 'copy -f $msg /tmp/draft$$ ; mail -draft /tmp/draft$$'
  74.     sh rm /tmp/draft$$
  75. }
  76. button "Use As Composition" use_as_composition
  77.  
  78. function msg_diff() {
  79. #%
  80. #      msg_diff [messagelist]
  81. #
  82. # Run the "diff" program on the two messages and display the result.
  83. # If more than two messages are passed to this function, the first and
  84. # last in the list are compared.
  85. #%
  86.     if $?input
  87.     set - $input
  88.     endif
  89.     pick +1 -r $* | write -f /tmp/msg$$ | flags -S
  90.     pick -1 -r $* | Pipe "diff - /tmp/msg$$ > /tmp/diff$$"
  91.     page /tmp/diff$$
  92.     sh rm /tmp/diff$$ /tmp/msg$$
  93. }
  94. button Diff msg_diff
  95.  
  96. function set_reply_to() {
  97. #%
  98. #     set_reply_to [message-number]
  99. #
  100. # Sets the varible "$reply_to" to the reply address taken from the
  101. # indicated message.  BUG: Does not attempt to track $reply_to_hdr.
  102. #%
  103.     msg_list - $1
  104.     unset reply_to
  105.     if $?[%?reply-to?]
  106.     set reply_to = "$[%?reply-to?]"
  107.     else
  108.     if $?[%?from?]
  109.         set reply_to = "$[%?from?]"
  110.     else
  111.         if $?[%?return-path?]
  112.         set reply_to = "$[%?return-path?]"
  113.         endif
  114.     endif
  115.     endif
  116. }
  117.  
  118. function collect_addrs() {
  119.     set_reply_to $1
  120.     if $?reply_to
  121.     if $?addrs
  122.         # Fast test for "Did I already use this address?"
  123.         # Not always correct, but errs conservatively.
  124.         if "$addrs" !~ *"$reply_to"*
  125.         set addrs = "$addrs, $reply_to"
  126.         endif
  127.     else
  128.         set addrs = "$reply_to"
  129.     endif
  130.     endif
  131.     return 0
  132. }
  133.  
  134. function alias_to() {
  135. #%
  136. #     alias_to message-numbers alias-name
  137. #
  138. # Create an alias named alias-name that maps to the senders
  139. # of all the listed message-numbers.
  140. #%
  141.     unset addrs msgs
  142.     shift -m | set msgs
  143.     if $?msgs
  144.     each $msgs collect_addrs
  145.     else
  146.     error "usage: alias_to message-numbers alias-name"
  147.     return -1
  148.     endif
  149.     if $# == 0
  150.     ask -i name "Enter name for alias:"
  151.     if $status != 0
  152.         return
  153.     endif
  154.     else
  155.     set name = "$*"
  156.     endif
  157.     alias "$name" "$addrs"
  158.     unset addrs msgs name reply_to
  159. }
  160. button "Alias To" alias_to
  161.